{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 数值类变量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 布尔变量(bool)\n",
    "布尔变量(bool)是整数型变量(int)的子类。当整数型变量的值为0时，布尔变量的值为False；当整数型变量的值非0时，布尔变量的值为True。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 赋值方法\n",
    "布尔变量可以直接用常量赋值构建(1-2)，也可以使用bool()函数构建(3-7)；此外，条件语句的返回结果也是布尔变量(8)。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:44:54.285391Z",
     "start_time": "2020-04-25T09:44:54.280431Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True False True False False True True False\n"
     ]
    }
   ],
   "source": [
    "var_1 = True\n",
    "var_2 = False\n",
    "var_3 = bool(True)\n",
    "var_4 = bool(False)\n",
    "var_5 = bool(0)\n",
    "var_6 = bool(1)\n",
    "var_7 = bool(2)\n",
    "var_8 = 30>30\n",
    "print(var_1, var_2, var_3, var_4, var_5, var_6, var_7, var_8)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 基础运算\n",
    "布尔变量在执行减加乘除等数值运算时，就是整数0和1的运算。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:54:24.590338Z",
     "start_time": "2020-04-25T09:54:24.583358Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n",
      "True\n",
      "True\n",
      "True\n",
      "True+1 : 2\n",
      "True-1 : 0\n",
      "True*2 : 2\n",
      "True/2 : 0.5\n"
     ]
    }
   ],
   "source": [
    "var_1, var_2 = True, False\n",
    "print(var_1 and var_2)\n",
    "print(var_1 or var_2)\n",
    "print(var_1 and not var_2)\n",
    "print(var_1 or not var_2)\n",
    "print(\"True+1\", \":\", var_1 + 1)\n",
    "print(\"True-1\", \":\", var_1 - 1)\n",
    "print(\"True*2\", \":\", var_1 * 2)\n",
    "print(\"True/2\", \":\", var_1 / 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 整数变量(int)、浮点数变量(float)\n",
    "在Python3以后，长整型(long)被移除，使用int代替 "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 赋值方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:47:26.183775Z",
     "start_time": "2020-04-25T09:47:26.179783Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3 3 3.1415926 3.0\n"
     ]
    }
   ],
   "source": [
    "# 整数变量\n",
    "var_1 = 3\n",
    "var_2 = int(3.1415926)\n",
    "# 浮点数变量\n",
    "var_3 = 3.1415926\n",
    "var_4 = float(3)\n",
    "print(var_1, var_2, var_3, var_4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 基础运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:55:39.175966Z",
     "start_time": "2020-04-25T09:55:39.169990Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10+3 : 13\n",
      "10-3 : 7\n",
      "10*3 : 30\n",
      "10/3 : 3.3333333333333335\n",
      "10^3 : 1000\n",
      "10/3取模 : 3\n",
      "10/3取余 : 1\n"
     ]
    }
   ],
   "source": [
    "var_1, var_2 = 10, 3\n",
    "print(\"10+3\", \":\", var_1 + var_2)\n",
    "print(\"10-3\", \":\", var_1 - var_2)\n",
    "print(\"10*3\", \":\", var_1 * var_2)\n",
    "print(\"10/3\", \":\", var_1 / var_2)\n",
    "print(\"10^3\", \":\", var_1 ** var_2)\n",
    "print(\"10/3取模\", \":\", var_1 // var_2)\n",
    "print(\"10/3取余\", \":\", var_1 % var_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 复数变量(complex)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 赋值方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:48:53.993570Z",
     "start_time": "2020-04-25T09:48:53.988584Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(2+0j) (2+1j) (2+0j) (2+1j)\n"
     ]
    }
   ],
   "source": [
    "var_1 = complex(2)\n",
    "var_2 = complex(2,1)\n",
    "var_3 = complex(\"2\")\n",
    "var_4 = complex(\"2+1j\")\n",
    "print(var_1, var_2, var_3, var_4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 基础运算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:56:32.981260Z",
     "start_time": "2020-04-25T09:56:32.976273Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(3-1j)\n",
      "(1+3j)\n",
      "(4-3j)\n",
      "(-0+1j)\n"
     ]
    }
   ],
   "source": [
    "var_1, var_2 = complex(2,1), complex(1,-2)\n",
    "print(var_1 + var_2)\n",
    "print(var_1 - var_2)\n",
    "print(var_1 * var_2)\n",
    "print(var_1 / var_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T02:01:45.045011Z",
     "start_time": "2020-04-25T02:01:45.040032Z"
    }
   },
   "source": [
    "# 序列类变量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T05:14:45.134566Z",
     "start_time": "2020-04-25T05:14:45.130575Z"
    }
   },
   "source": [
    "## 字节变量(bytes)\n",
    "字节变量(bytes)是不可变的字节序列，对它的任何操作都不会改变它自身；字节变量在很多方法上与字符串(str)十分相似。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:50:16.755431Z",
     "start_time": "2020-04-25T09:50:16.750446Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "b'hello' b'hello'\n"
     ]
    }
   ],
   "source": [
    "var_1 = b\"hello\"\n",
    "var_2 = bytes(b\"hello\")\n",
    "print(var_1, var_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字节数组(bytearray)\n",
    "字节数组(bytearray)是可变的字节序列，既拥有部分字节变量的操作方法，可以像字符串一样被操作；也拥有一部分列表(list)的操作方法，可以像列表一样被操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:50:48.833263Z",
     "start_time": "2020-04-25T09:50:48.829294Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "bytearray(b'hello') 68656c6c6f bytearray(b'hello')\n"
     ]
    }
   ],
   "source": [
    "var_1 = bytearray(b\"hello\")\n",
    "var_2 = bytearray.fromhex(\"68656c6c6f\") # 十六进制的hello\n",
    "print(var_1, var_1.hex(), var_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T05:38:59.468271Z",
     "start_time": "2020-04-25T05:38:59.465279Z"
    }
   },
   "source": [
    "## 字符串(str)\n",
    "字符串(str)是不可变的字符序列，对它的任何操作都北湖汇改变它自身。Python中拥有一系列针对于字符串的操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:51:08.755499Z",
     "start_time": "2020-04-25T09:51:08.750514Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello hello\n"
     ]
    }
   ],
   "source": [
    "var_1 = \"hello\"\n",
    "var_2 = str(\"hello\")\n",
    "print(var_1, var_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 列表(list)\n",
    "列表(list)是一个有序的、可重复的、每个元素均可以被修改的元素序列，列表中的每一个元素都分配了一个索引。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:51:40.160582Z",
     "start_time": "2020-04-25T09:51:40.155597Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['h', 'e', 'l', 'l', 'o', 3, 3.1415926]\n",
      "h\n",
      "['l', 'o']\n"
     ]
    }
   ],
   "source": [
    "var_1 = [\"h\", \"e\", \"l\", \"l\", \"o\", 3, 3.1415926]\n",
    "print(var_1)\n",
    "print(var_1[0])\n",
    "print(var_1[3:5])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 元组(tuple)\n",
    "元组(tuple)是一个有序的、可重复的、每个元素均不能被修改的元素序列；与列表(list)类似，为每一个元素都分配了一个索引。与列表不同的是，元组中的元素不能被修改。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:52:01.016291Z",
     "start_time": "2020-04-25T09:52:01.011304Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('h', 'e', 'l', 'l', 'o', 3, 3.1415926)\n",
      "h\n",
      "('l', 'o')\n"
     ]
    }
   ],
   "source": [
    "var_1 = (\"h\", \"e\", \"l\", \"l\", \"o\", 3, 3.1415926)\n",
    "print(var_1)\n",
    "print(var_1[0])\n",
    "print(var_1[3:5])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 容器类变量"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 集合(set)\n",
    "集合(set)是一个无序的、不重复的元素序列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:52:52.325574Z",
     "start_time": "2020-04-25T09:52:52.320588Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'l', 'e', 'h', 'o'} {'l', 'e', 'h', 'o'}\n"
     ]
    }
   ],
   "source": [
    "var_1 = {\"h\", \"e\", \"l\", \"l\", \"o\"}\n",
    "var_2 = set(\"hello\")\n",
    "print(var_1, var_2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 字典(dict)\n",
    "字典(dict)是一种可变的容器模型，使用对象(object)和数组(array)两种结构来组合成复杂的数据结构。其中对象是一个无序的“键值对”集合，键必须是唯一的，但是值不一定是唯一的；数组是值的有序集合，即列表(list)。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2020-04-25T09:53:03.321552Z",
     "start_time": "2020-04-25T09:53:03.317553Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'hello': ['h', 'e', 'l', 'l', 'o'], 'circle': 3.1415926}\n"
     ]
    }
   ],
   "source": [
    "var_1 = {\"hello\": [\"h\", \"e\", \"l\", \"l\", \"o\"], \"circle\": 3.1415926}\n",
    "print(var_1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
